package com.block.datapush.service.apipush.utils;

import cn.hutool.core.util.StrUtil;
import com.block.common.enums.BaseTypeInfoEnum;

import javax.crypto.Cipher;
import javax.crypto.spec.SecretKeySpec;
import java.math.BigDecimal;
import java.nio.charset.StandardCharsets;

/**
 * 81 大麦花花  回调
 */
public class XinFengUtil {
    private static final String ALGORITHMSTR = "AES/ECB/PKCS5Padding";
    private static final String AES = "AES";

    //贷款期限
    public static BigDecimal getLoanAmount(String loanAmount) {
        if (StrUtil.equals(loanAmount, BaseTypeInfoEnum.LoanAmount.la001.getValue())) {
            return BigDecimal.valueOf(30000);
        } else if (StrUtil.equals(loanAmount, BaseTypeInfoEnum.LoanAmount.la002.getValue())) {
            return BigDecimal.valueOf(50000);
        } else if (StrUtil.equals(loanAmount, BaseTypeInfoEnum.LoanAmount.la003.getValue())) {
            return BigDecimal.valueOf(100000);
        } else if (StrUtil.equals(loanAmount, BaseTypeInfoEnum.LoanAmount.la004.getValue())) {
            return BigDecimal.valueOf(200000);
        }
        return BigDecimal.valueOf(250000);
    }

    //贷款时间
    public static Integer getLoanTerm(String loanTime) {
        if (StrUtil.equals(loanTime, BaseTypeInfoEnum.LoanTime.lt001.getValue())) {
            return 3;
        }
        return 12;
    }

    //贷款用途
    public static Integer getLoanUse(String yongtu) {
        if (StrUtil.equals(yongtu, BaseTypeInfoEnum.Yongtu.yt001.getValue())) {
            return 3;
        }
        return 0;
    }

    //职业身份
    public static Integer getJob(String jbo) {
        if (StrUtil.equals(jbo, BaseTypeInfoEnum.Gongzuo.gz001.getValue())) {
            return 2;
        } else if (StrUtil.equals(jbo, BaseTypeInfoEnum.Gongzuo.gz002.getValue())) {
            return 4;
        } else if (StrUtil.equals(jbo, BaseTypeInfoEnum.Gongzuo.gz003.getValue())) {
            return 1;
        } else if (StrUtil.equals(jbo, BaseTypeInfoEnum.Gongzuo.gz004.getValue())) {
            return 3;
        }
        return 1;
    }

    //收入
    public static BigDecimal getShouru(String shouru) {
        if (StrUtil.equals(shouru, BaseTypeInfoEnum.Shouru.sr001.getValue())) {
            return BigDecimal.valueOf(2000);
        } else if (StrUtil.equals(shouru, BaseTypeInfoEnum.Shouru.sr002.getValue())) {
            return BigDecimal.valueOf(5000);
        } else if (StrUtil.equals(shouru, BaseTypeInfoEnum.Shouru.sr003.getValue())) {
            return BigDecimal.valueOf(10000);
        }
        return BigDecimal.valueOf(15000);
    }

    //学历
    public static Integer getXueli(String xueli) {
        if (StrUtil.equals(xueli, BaseTypeInfoEnum.XueLi.xl001.getValue())) {
            return 1;
        } else if (StrUtil.equals(xueli, BaseTypeInfoEnum.XueLi.xl003.getValue())) {
            return 3;
        } else if (StrUtil.equals(xueli, BaseTypeInfoEnum.XueLi.xl004.getValue())) {
            return 4;
        } else if (StrUtil.equals(xueli, BaseTypeInfoEnum.XueLi.xl005.getValue())) {
            return 6;
        }
        return 2;
    }

    //芝麻
    public static Integer getZhima(String zhima) {
        if (StrUtil.equals(zhima, BaseTypeInfoEnum.Zhima.zm001.getValue())) {
            return 0;
        } else if (StrUtil.equals(zhima, BaseTypeInfoEnum.Zhima.zm003.getValue())) {
            return 3;
        } else if (StrUtil.equals(zhima, BaseTypeInfoEnum.Zhima.zm004.getValue())) {
            return 4;
        } else if (StrUtil.equals(zhima, BaseTypeInfoEnum.Zhima.zm005.getValue())) {
            return 5;
        }
        return 2;
    }

    //逾期
    public static Integer getYuqi(String yuqi) {
        if (StrUtil.equals(yuqi, BaseTypeInfoEnum.Yuqi.yq001.getValue())) {
            return 2;
        }
        return 1;
    }

    //保险
    public static Integer getBaoxian(String baoxian) {
        if (StrUtil.equals(baoxian, BaseTypeInfoEnum.Baoxian.bx001.getValue())) {
            return 0;
        }
        return 1;
    }

    //房产
    public static Integer getHouse(String house) {
        if (StrUtil.equals(house, BaseTypeInfoEnum.House.hu001.getValue())) {
            return 0;
        }
        return 2;
    }
    //车产
    public static Integer getCar(String car) {
        if (StrUtil.equals(car, BaseTypeInfoEnum.Car.car001.getValue())) {
            return 0;
        }
        return 2;
    }

    //社保和公积金
    public static Integer getShebaoAndGjj(String shebao, String gjj) {
        boolean Shebao = StrUtil.equalsAny(shebao, "sb002", "sb003");
        boolean Gjj = StrUtil.equalsAny(gjj, "gjj002", "gjj003");

        if (Shebao && Gjj) {
            return 1; // 都有
        } else if (Shebao) {
            return 2; // 仅社保
        } else if (Gjj) {
            return 3; // 仅公积金
        }
        return 4; // 都没有

    }

    public static void main(String[] args) {
        Integer shebaoAndGjj = getShebaoAndGjj("sb001", "gjj003");
        System.out.println(shebaoAndGjj);

    }


    public static Integer getShebao(String shebao) {
        if (StrUtil.equals(shebao, BaseTypeInfoEnum.Shebao.sb001.getValue())) {
            return 0;
        }
        return 2;
    }

    public static Integer getGjj(String gjj) {
        if (StrUtil.equals(gjj, BaseTypeInfoEnum.Gjj.gjj001.getValue())) {
            return 0;
        }
        return 2;
    }

    public static Integer getHuaBei(String huabei) {
        if (StrUtil.equals(huabei, BaseTypeInfoEnum.Huabei.hb001.getValue())) {
            return 0;
        }
        return 1;
    }

    public static Integer getBaiTiao(String baotiao) {
        if (StrUtil.equals(baotiao, BaseTypeInfoEnum.Baitiao.bt001.getValue())) {
            return 0;
        }
        return 1;
    }

    public static String encryptUtf8(String str, String key) {
        try {
            byte[] raw = key.getBytes(StandardCharsets.UTF_8);
            SecretKeySpec secretKeySpec = new SecretKeySpec(raw, AES);
            Cipher cipher = Cipher.getInstance(ALGORITHMSTR);
            cipher.init(Cipher.ENCRYPT_MODE, secretKeySpec);
            byte[] encrypted = cipher.doFinal(str.getBytes(StandardCharsets.UTF_8));
            return java.util.Base64.getEncoder().encodeToString(encrypted);
        } catch (Exception e) {
            return null;
        }
    }

    public static Integer getXyk(String xinyongka) {
        if(StrUtil.equals(xinyongka,BaseTypeInfoEnum.XinYongKa.xyk001.getValue())) {
            return 0;
        }
        return 1;
    }
}
